import pandas as pd
def PET_Ex(i_path,o_path):
    with open(i_path, "r", encoding="utf-8") as f:
        lines = f.readlines()

    processed_lines = []
    for line in lines:
        line = line.strip()
        if not line:
            continue
        parts = line.split("\t")
        if len(parts) == 2:
            e_tag = parts[0]
            num = e_tag[1:]
            new_content = f"{parts[1]}\tE{num},{parts[1]}"
            processed_lines.append(new_content)
        else:

            processed_lines.append(line)
    with open(o_path, "w", encoding="utf-8") as f:
        f.write("\n".join(processed_lines))
def PET_Ex2(i_path,o_path):
    input_path = "Linux_2k.log_templates.txt"
    output_path = "processed_Linux_2k.log_templates.txt"
    df = pd.read_csv(
        i_path,
        sep="\t",
        header=None,
        names=["error_label", "event_template"],
        encoding="utf-8"
    )
    df["error_label"] = df["error_label"].str.replace(
        r"error(\d+)",
        r"error##\1",
        regex=True      )

    df.to_csv(
        o_path,
        sep="\t",
        header=False,
        index=False,
        encoding="utf-8"
    )
if __name__ == "__main__":

    PET_Ex2(r"C:\Users\Lenovo\Desktop\挑战杯“挂帅揭榜”\bert\BERT-PET\PET\data\processed_linux\Linux_2k.log_templates.txt",r"C:\Users\Lenovo\Desktop\挑战杯“挂帅揭榜”\bert\BERT-PET\PET\data\processed_linux\Linux_templates.txt")